16 #ifdef __MSP430_HAS_EUSCI_Bx__
21 void EUSCI_B_SPI_initMaster (uint16_t baseAddress,
22 EUSCI_B_SPI_initMasterParam *
param)
25 HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
28 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
29 UCMST + UCMODE_3 + UCSYNC);
32 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSSEL_3);
35 HWREG16(baseAddress + OFS_UCBxCTLW0) |= (uint16_t)
param->selectClockSource;
37 HWREG16(baseAddress + OFS_UCBxBRW) =
38 (uint16_t)(
param->clockSourceFrequency /
param->desiredSpiClock);
47 HWREG16(baseAddress + OFS_UCBxCTLW0) |= (
50 param->clockPolarity +
57 void EUSCI_B_SPI_select4PinFunctionality (uint16_t baseAddress,
58 uint16_t select4PinFunctionality
61 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCSTEM;
62 HWREG16(baseAddress + OFS_UCBxCTLW0) |= select4PinFunctionality;
65 void EUSCI_B_SPI_changeMasterClock (uint16_t baseAddress,
66 EUSCI_B_SPI_changeMasterClockParam *
param)
69 HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
71 HWREG16(baseAddress + OFS_UCBxBRW) =
72 (uint16_t)(
param->clockSourceFrequency /
param->desiredSpiClock);
75 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
78 void EUSCI_B_SPI_initSlave (uint16_t baseAddress, EUSCI_B_SPI_initSlaveParam *
param)
81 HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
84 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCMSB +
93 HWREG16(baseAddress + OFS_UCBxCTLW0) |= (
param->clockPhase +
94 param->clockPolarity +
101 void EUSCI_B_SPI_changeClockPhasePolarity (uint16_t baseAddress,
103 uint16_t clockPolarity
107 HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
109 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCCKPH + UCCKPL);
111 HWREG16(baseAddress + OFS_UCBxCTLW0) |= (
117 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
120 void EUSCI_B_SPI_transmitData ( uint16_t baseAddress,
127 uint8_t EUSCI_B_SPI_receiveData (uint16_t baseAddress)
129 return (
HWREG16(baseAddress + OFS_UCBxRXBUF)) ;
132 void EUSCI_B_SPI_enableInterrupt (uint16_t baseAddress,
136 HWREG16(baseAddress + OFS_UCBxIE) |= mask;
139 void EUSCI_B_SPI_disableInterrupt (uint16_t baseAddress,
143 HWREG16(baseAddress + OFS_UCBxIE) &= ~mask;
146 uint8_t EUSCI_B_SPI_getInterruptStatus (uint16_t baseAddress,
150 return (
HWREG16(baseAddress + OFS_UCBxIFG) & mask );
153 void EUSCI_B_SPI_clearInterrupt (uint16_t baseAddress,
157 HWREG16(baseAddress + OFS_UCBxIFG) &= ~mask;
160 void EUSCI_B_SPI_enable (uint16_t baseAddress)
163 HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
166 void EUSCI_B_SPI_disable (uint16_t baseAddress)
169 HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
172 uint32_t EUSCI_B_SPI_getReceiveBufferAddress (uint16_t baseAddress)
174 return ( baseAddress + OFS_UCBxRXBUF );
177 uint32_t EUSCI_B_SPI_getTransmitBufferAddress (uint16_t baseAddress)
179 return ( baseAddress + OFS_UCBxTXBUF );
182 uint16_t EUSCI_B_SPI_isBusy (uint16_t baseAddress)
185 return (
HWREG16(baseAddress + OFS_UCBxSTATW) & UCBUSY);
MPU_initThreeSegmentsParam param